

type Year = number
type Month = number
type Day = number
type dateTime = Array<number>

class DatePicker {
    dateItems: dateTime;
    year: Year;
    month: Month;

    constructor(year?: Year, month?: Month) {
        this.year = year || this.getYear(new Date());
        this.month = month || this.getMonth(new Date());
        this.dateItems = this.getDateItem(this.year, this.month)
    }
    getDateItem(year: Year, month: Month,): dateTime {
        let dateRule = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            //  闰年 
            dateRule = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
        }
        const data: dateTime = [];
        for (let index = 1; index <= dateRule[month]; index++) {
            data.push(index)
        }
        return data
    }
    /**
     *  提取日期中的年份
     * @param date 
     */
    getYear(date): Year {
        return new Date(date).getFullYear()
    }
    /**
     * 提取日期中的月份
     * @param date 
     */
    getMonth(date): Month {
        return new Date(date).getMonth() + 1
    }
    /**
     * 
     * 获取传入的日期的相邻两个月的 日期表
     * 
     * @param date 
     */
    getSelfAndSiblingDate(date) {
        const month = this.getMonth(date)
        const year = this.getYear(date)
        if(month == 12){
            
        }
        const data = {
            prev: {
                year,
                month: month - 1,
                day: this.getDateItem(year, month - 1)
            },
            current: {
                year,
                month,
                day: this.getDateItem(year, month)
            },
            next: {
                year,
                month: month + 1,
                day: this.getDateItem(year, month + 1)
            }
        }
        return data
    }

    // 一：如果年的数目是 4 的倍数，就是闰年。 <br>　　
    // 二：但是，如果年的数目是 100 的倍数，规则一就无效，仍是常年。 <br>　　
    // 三：但是，如果年的数目是 400 的倍数，规则二就无效，仍是闰年。
}

const date = new DatePicker()





console.log(date)